package core

import (
	"fmt"
	"gopkg.in/yaml.v2"
	"gvb_server/config"
	"gvb_server/global"
	"log"
	"os"
)

func InitConf() {
	const ConfigFile = "settings.yaml"
	InitConfByPath(ConfigFile)
}

func InitConfByPath(path string) {
	c := &config.Config{}
	yamlConf, err := os.ReadFile(path)
	if err != nil {
		panic(fmt.Errorf("get yamlConf error:%s", err))
	}
	err = yaml.Unmarshal(yamlConf, c)
	if err != nil {
		log.Fatalf("config Init Unmarshal: %v", err)
	}
	log.Println("config yaml file load Init success.")
	//configJson, _ := json.Marshal(c)
	//log.Println("config:", string(configJson))
	global.Config = c
}
